package com.IR.user.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.IR.shop.mapper.UsersMapper;
import com.IR.shop.po.Users;
@Service
public class AUsersBiz {
	
	@Resource
	public UsersMapper usersmapper;

	
	//�û���ӣ������������Ϣ
	@SuppressWarnings("finally")
	public int saveUser() {
		Users users1 = new Users();
		//�û�������΢��ͷ�񱣴�
		users1.setUsername("username");
		users1.setUserimg("userimg");
		//ע��ʱ�䴦��
		Date d = new Date();
		users1.setUserdate(d);
		//�û�����Ĭ��Ϊ0
		users1.setIntegral(0);
		//ʱ�� ����
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmssSSS"); 
		String datestr=sdf.format(d);
		//�û�id,Ψһ������
		users1.setUserid(new Long(datestr));
		users1.setUsercode(datestr);
		//Ĭ��Ϊ��
		users1.setUsersex("男");
		users1.setUsermoney(40.25);
		//����moneys������
		/*Moneys m = new Moneys();
		m.setUserid(new Long(datestr));
		m.setUsermoney((double) 0.0);*/
		//�������ݿ�
		int result = 0;
		try {
			result = usersmapper.insert(users1);
			//result = moneysmapper.insert(m);
		} catch (Exception e) {
			// TODO: handle exception
		}finally {
			return result;
		}
		//System.out.println(result);
		//���ؽ��ֵ���Ϊ1����ɹ������Ϊ0��ʧ��	
	}
	
	//���������޸�
	@SuppressWarnings("finally")
	public int updateUser(Long userid,String username,String usersex,int userage,Long userphone,String userremark) {
		Users users1=usersmapper.selectByPrimaryKey(userid);
		users1.setUserage(userage);
		users1.setUserphone(userphone);
		users1.setUsersex(usersex);
		users1.setUsername(username);
		users1.setUserremark(userremark);
		int result=0;
		try {
			//�޸����ݿ��������
			usersmapper.updateByPrimaryKey(users1);
		} catch (Exception e) {
			// TODO: handle exception
		}finally {
			//System.out.println(result);
			return result;
		}
	}
	public void usermoneyUp() {
		Users users1=usersmapper.selectByPrimaryKey(111111111l);
		double d=0.50;
		users1.setUsermoney(users1.getUsermoney()+d);
		usersmapper.updateByPrimaryKey(users1);
	}
	public void usermoneyDown() {
		Users users1=usersmapper.selectByPrimaryKey(111111111l);
		double d=0.50;
		users1.setUsermoney(users1.getUsermoney()-d);
		usersmapper.updateByPrimaryKey(users1);
	}
}
